package com.ssm.sfzy.controller;

import com.ssm.sfzy.constant.CommonConstant;
import com.ssm.sfzy.entity.HeartMark;
import com.ssm.sfzy.service.HeartMarkService;
import com.ssm.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author fuyanru
 * @date 2024年03月30日 10:40
 */
@RestController
@CrossOrigin
@RequestMapping("/heartMark")
public class HeartMarkController {
    @Autowired
    private HeartMarkService heartMarkService;
    @GetMapping("/findById/{id}")
    public Object findById(@PathVariable int id){
        HeartMark heartMark = heartMarkService.findById(id);
        return Result.success(heartMark);
    }
    @GetMapping("/find")
    public Object find(
            @RequestParam(defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
            @RequestParam(defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
            HeartMark heartMark
    ){
        Map<String, Object> map = heartMarkService.findPage(pageNum, pageSize, heartMark);
        return  Result.success(map);
    }
    @PostMapping("/add")
    public Object add(@RequestBody HeartMark heartMark) throws Exception {
        heartMarkService.add(heartMark);
        return Result.success();
    }

    @PutMapping("/edit")
    public Object edit(@RequestBody HeartMark heartMark)  {
        heartMarkService.edit(heartMark);
        return Result.success();
    }
    @DeleteMapping("/remove/{id}")
    public Object remove(@PathVariable int id){
        heartMarkService.remove(id);
        return Result.success();
    }

    @DeleteMapping("/removeBatch")
    public Object remove(Integer[] ids){
        System.out.println(ids);
        heartMarkService.removeBatch(ids);
        return Result.success();
    }
}
